Skip to content

Feat: add steam-style launch options wrapper around a game - #25

Open
pekac45 wants to merge 2 commits into
LightforgeProject:mainfrom
pekac45:feat/game-hooks
Open

pekac45 wants to merge 2 commits into
LightforgeProject:mainfrom
pekac45:feat/game-hooks

Conversation

@pekac45

@pekac45 pekac45 commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Adds a per-game Launch options field to Game Settings. It works like Steam's: a command line with %command% where the game goes. Use it to run host programs around a game, such as a helper app that should run only while WoW does, without a watcher script polling for the game.

kcalc & %command%; pkill -x kcalc

How it runs

  • Games Lightforge starts (Play, lightforge play): the options wrap the game, outermost as on Steam. The order is: the options, then game-performance, then Proton. %command% becomes "$@", so sh -c gets the game's command as arguments and never parses it.
  • Games Battle.net starts (HotS, Diablo, and WoW when launched through Battle.net): launching sends a message to the running client, so there is nothing to wrap. Instead the line runs once the game is up, and %command% waits for the game to exit (tail --pid). A script that does things before and after %command% behaves the same in both cases.
  • A line without %command% does nothing, and the field says so. Steam would add such a line to the game's arguments, but a Battle.net launch can't take arguments.
  • The line runs through sh on the host, not in the prefix. Nothing touches the game.

In the Battle.net case, the line runs in its own process group, so its cleanup still runs after a Ctrl+C in the launcher's terminal. Its stderr is drained so a program that prints a lot isn't killed by SIGPIPE. If the line fails, the first 4 KiB of stderr go to the log.

Each game's line is saved as launch_options in config.toml. It's left out when empty, so existing configs save unchanged.

Testing

  • cargo test passes (1021 tests), cargo clippy --all-targets reports nothing, and docs/CLI.md is unchanged because there are no new flags.
  • New tests in crates/core/src/launch_options.rs check that:
    • a line without %command% runs nothing
    • the game's arguments arrive unchanged, including spaces, $HOME, quotes and a literal %command%
    • the wrapped game keeps its environment and working folder
    • a script runs before and after the game
    • beside a running game, the part after %command% waits for the game to exit
    • a line that writes more to stderr than the pipe holds still runs to the end
    • a profile without launch options saves as before
  • GUI test: the field shows the selected game's line and saves once typing pauses.
  • Tested by hand:
    • the kcalc line around WoW started from Play
    • with WoW started through Battle.net, systemctl --user start tsm.service; %command%; sleep 30; … started TSM with the game and stopped it a 30 seconds after the game exited

Not covered by automated tests: whether a Battle.net launch picks up the right game's line (that needs a running client), and lightforge play end to end (that needs an install).

A per-product line with %command% where the game goes, as Steam takes
it, for native programs that belong beside one game: a TSM AppImage
behind a systemd unit, which neither Game Tools (Windows programs) nor
game-performance (it wraps Battle.net, which outlives the game) can
start and stop.

A game Lightforge starts is wrapped for real, outside game-performance.
One Battle.net starts cannot be, so there the line runs once the game is
up and %command% waits for it to exit: a script that starts helpers,
runs "$@" and cleans up after works for both. lightforge play honours
the line too, as it does every other per-product setting.
One field per game, saved once typing pauses as the environment editor
is. A hand-off runs the line beside the game once it is in the process
table, and the field says so, since a wrapper there has nothing around
it to wrap.
@simplykenny

Copy link
Copy Markdown
Member

Hey, sounds good and i will check it when i am at home

@simplykenny

Copy link
Copy Markdown
Member

Thanks, this is really well done. Merged into dev (rebased onto the launch changes there), with a small hint added that %command% has to stay in the foreground. It'll be in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants